package gamecomm.library;

// DONE: Add a field for the timestamp 
import static android.provider.BaseColumns._ID;

import java.util.HashMap;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import static gamecomm.library.Constants.ITEM;
import static gamecomm.library.Constants.TABLE_NAME;

public class GamesDatabase extends SQLiteOpenHelper {
	   private static final String DATABASE_NAME = "gamesdb.db";
	   private static final int DATABASE_VERSION = 7;
	   /*OnCreate is called when we create the database. It is passed the SQLiteDatabase reference, 
	    * which we can use to perform various operations on the database. In this method, we use the function execSQL 
	    * to execute an SQL query to create a table called TABLE_NAME which has three columns. The first column, (_id) 
	    * is required to generate a unique id for each column. This is necessary in case you are going to use classes like 
	    * SimpleCursorAdapter
	    * The second column (ITEM) is the data field that we want to actualy store.	    */
	   /** Create a helper object for the Items database */
	  
	   public GamesDatabase(Context ctx) { 
	      super(ctx, DATABASE_NAME, null, DATABASE_VERSION);
	   }

	   @Override
	   // DONE: When creating the database, add an int field for the timestamp
	   public void onCreate(SQLiteDatabase db) { 
	      db.execSQL("CREATE TABLE " + TABLE_NAME + " (" + _ID
	    		  + " INTEGER PRIMARY KEY AUTOINCREMENT, " + ITEM + " UNIQUE);");
	             // + " INTEGER PRIMARY KEY AUTOINCREMENT, " + ITEM + " TEXT NOT NULL);");
	    
	   }

	   @Override
	   public void onUpgrade(SQLiteDatabase db, int oldVersion, 
	         int newVersion) {
	      db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
	      onCreate(db);
	   }
	   
	/*   CREATE TABLE IF NOT EXISTS x (
    _id integer primary key autoincrement, 
    name text unique);
CREATE TABLE IF NOT EXISTS y (
    _id integer primary key autoincrement, 
    address text unique,
    xid references x(_id));
    
    public HashMap<String, String> getGameDetails(){
	        HashMap<String,String> user = new HashMap<String,String>();
	        String selectQuery = "SELECT  * FROM " + TABLE_NAME;
	 
	        SQLiteDatabase db = this.getReadableDatabase();
	        Cursor cursor = db.rawQuery(selectQuery, null);
	        // Move to first row
	        cursor.moveToFirst();
	        if(cursor.getCount() > 0){
	            user.put("item", cursor.getString(1));
	            
	        }
	        cursor.close();
	        db.close();
	        // return user
	        return user;
	    }
	   */
	   
	}

